package com.gitee.itembucket.util.germ

import com.germ.germplugin.api.dynamic.gui.GermGuiScreen
import com.germ.germplugin.api.dynamic.gui.GermGuiTexture
import com.gitee.itembucket.util.germ.germ.GermPartDSL
import taboolib.library.configuration.ConfigurationSection

class GermTextureDSL : GermPartDSL<GermGuiTexture>() {

    var path = ""
    var width = ""
    var height = ""

    override val type: String = "texture"

    var onClick: (GermGuiScreen.() -> Unit)? = null

    override fun infuse(config: ConfigurationSection) {
        name = config.name
        config.getString("locationX")?.let { locationX = it }
        config.getString("locationY")?.let { locationY = it }
        config.getString("locationZ")?.let { locationZ = it }
        config.getString("path")?.let { path = it }
        config.getString("width")?.let { width = it }
        config.getString("height")?.let { height = it }
        config.getString("width")?.let { width = it }

        enable = config.getBoolean("enable")
    }

    override fun create(): GermGuiTexture {
        return GermGuiTexture(name).also {
            it.locationX = locationX
            it.locationY = locationY
            it.locationZ = locationZ
            it.enable = enable
            it.path = path
            it.width = width
            it.height = height
            onClick?.apply {
                it.registerCallbackHandler({ _, _ ->
                    onClick!!(it.germGuiScreen)
                }, GermGuiScreen.ClickType.LEFT_CLICK)
            }
        }
    }
}